package com.wpw.dream.threadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 有界队列
 * 
 * Project Name：dream-test
 * ClassName：ThreadPoolExcutorTest
 * Description：
 * @author: wupengwei
 * @date: 2017年5月15日 下午11:00:15
 * note:
 *
 */
public class ThreadPoolExcutorTest implements Runnable {
	
	
	public String name;
	
	public ThreadPoolExcutorTest(String name) {
		this.name = name;
	}
	
	@Override
	public void run() {
		System.out.println(name);
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
	}
	
	public static void main(String[] args) {
		BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(3);
		ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
							1, //corePoolSize
							2,	//maximumPoolSize
							1L,
							TimeUnit.SECONDS,
							workQueue
							);
		threadPool.execute(new ThreadPoolExcutorTest("任务1"));
		threadPool.execute(new ThreadPoolExcutorTest("任务2"));
		threadPool.execute(new ThreadPoolExcutorTest("任务3"));
		threadPool.execute(new ThreadPoolExcutorTest("任务4"));
		threadPool.execute(new ThreadPoolExcutorTest("任务5"));
		threadPool.execute(new ThreadPoolExcutorTest("任务6"));
		threadPool.shutdown();
		
	}


}
